﻿
//查询跳转
function GetMsgByAgentCode() {
    var AgentCode = $('#AgentCodeId').val();
    //$.post("/Mpa/Agent/GetMsgByAccountCode?AccountCode=" + AccountCode + "", function () { });
    var _url = "/Agent/GetMsgByAgentCode?AgentCode=" + AgentCode + "";
    abp.ajax({
        url: _url,
        //data: JSON.stringify(newAgent)
    }).done(function (data) {
        if (data.AgentCode != null) {
            $('#AgentCodeId').val(data.AgentCode);
            $('#AgentNameId').val(data.AgentName);
            $('#BalanceId').val(data.Balance);
            $('#IdCardId').val(data.IdCard);
            $('#TelephoneId').val(data.Telephone);
            $('#AdressId').val(data.Adress);
        }
        else {
            abp.message.warn("代理商账号不存在！");
        }
    });
}
//提交
function TransferSubmit() {
    var Balance = $("#TranferBalanceId").val();
    if (Balance % 1 === 0) {
        if ($('#AgentNameId').val() != "") {
            //逻辑校验
            if ($("#TranferBalanceId").val() == "" || $("#TranferBalanceId").val() == null) {
                abp.message.warn("请填写转账流量");
                return;
            }
            else {
                if (Number(Balance)) {
                    var absVal = Math.abs(Balance);
                    if (Balance != absVal) {
                        abp.message.warn("转账流量不能是负数");
                        return;
                    }
                }
                else {
                    abp.message.warn("转账流量请填写数字");
                    return;
                }
            }
            if ($("#AgentCodeId").val() == "" || $("#AgentCodeId").val() == null) {
                abp.message.warn("请填写转账账号");
                return;
            }
            var _url = "/Agent/AgentTransfers";
            var newAgent = {
                Quantity: $("#TranferBalanceId").val(),//转账流量
                ReceiveRechargeAgentCode: $("#AgentCodeId").val(),//转账账号
                Remark: $("#RemarkId").val()//备注
            };
            abp.ajax({
                url: _url,
                data: JSON.stringify(newAgent)
            }).done(function (data) {
                if (data.status == true) {
                    abp.message.confirm(
                        '转账成功！',
                        '是否继续转账?',//确认提示（可选参数）
                        function (isConfirmed) {
                            if (isConfirmed) {
                                //...
                                $('#AgentCodeId').val("");
                                $('#AgentNameId').val("");
                                $('#BalanceId').val("");
                                $('#IdCardId').val("");
                                $('#TelephoneId').val("");
                                $('#AdressId').val("");
                                $('#TranferBalanceId').val("");
                                $('#RemarkId').val("");
                            }
                            else {
                                window.location.href = "/Mpa/Agent/AgentTransferList";
                            }
                        }
                    );
                }
                if (data.status == false) {
                    abp.message.warn(data.errormsg);
                }
            });
        } else {
            abp.message.warn("代理商账号不存在！");
        }
    }
    else {
        abp.message.warn('转账流量应该大于0的整数！');
        return;
    }
}